package test;

import cn.dawn.webcollector.net.HttpRequest;
import cn.dawn.webcollector.net.HttpResponse;
import cn.dawn.webcollector.net.RequestConfig;

public class DemoHttpRequest {

	public static void demo1() throws Exception {
		HttpRequest request = new HttpRequest("http://www.csdn.net");

		HttpResponse response = request.getResponse();
		String html = response.getHtmlByCharsetDetect();

		System.out.println(html);
	}

	public static void demo2() throws Exception {
		RequestConfig requestConfig = new RequestConfig();
		requestConfig.setMethod("GET");
		requestConfig.setUserAgent("WebCollector");
		requestConfig.setCookie("xxxxxxxxxxxxxx");
		requestConfig.addHeader("xxx", "xxxxxxxxx");

		HttpRequest request = new HttpRequest("http://www.csdn.net", requestConfig);

		HttpResponse response = request.getResponse();
		String html = response.getHtmlByCharsetDetect();

		System.out.println(html);
		System.out.println("response code=" + response.getCode());
		System.out.println("Server=" + response.getHeader("Server"));
	}

	public static void main(String[] args) throws Exception {
		demo1();
		demo2();
	}
}
